home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Programmer's Toolkit
/
Java Programmer's Toolkit.iso
/
gs3.53
/
pdf_2ps.ps
< prev
next >
Wrap
Text File
|
1996-01-10
|
6KB
|
207 lines
% Copyright (C) 1994, 1995 Aladdin Enterprises. All rights reserved.
% pdf_2ps.ps
% PDF to PostScript additions to PDF reader.
GS_PDF_ProcSet begin
pdfdict begin
/.setlanguagelevel where { pop 2 .setlanguagelevel } if
.currentglobal true .setglobal
% Generate a sufficiently unique name (at least unique within the current
% save/restore environment).
/uniqueid#
{ userdict length
{ dup neg =string cvs dup 0 (_) putinterval cvn
userdict 1 index known not { exch pop exit } if pop 1 add
}
loop
} bdef
% "Wrap" all the runtime operators so they call #exec.
numargsdict
{ 1 index load exch 2 index exch /#exec cvx 4 packedarray cvx def
}
forall
/pdfmark
/pdfmark load dup type /operatortype eq { 1 packedarray cvx } if
{ /pdfmark counttomark 1 sub #exec } bind
aload length 1 add packedarray cvx
def
% Define #exec so it also prints out its arguments.
/dictwrite# % <file> <dict> dictwrite# -
{ dup length 240 le
{ 1 index (mark) writestring
{ 2 index ( ) writestring exch 2 index exch write#
1 index ( ) writestring 1 index exch write#
}
forall dup ( .dicttomark) writestring
}
{ 2 copy length write=only 1 index ( dict) writestring
{ exch 2 index dup ( dup ) writestring exch write#
1 index dup ( ) writestring exch write#
dup ( put) writestring
}
forall
}
ifelse pop
} bdef
/fontwrite# % <file> <font> fontwrite# -
{ % Find the named font and then modify it.
2 copy /FontName get =string cvs
{ dup dup length 1 sub 1 getinterval (%) ne { exit } if
0 1 index length 1 sub getinterval
}
loop cvn write==only
1 index ( findfont) writestring
% Insert the appropriate Encoding, by name if possible.
dup /Encoding get
dup dup StandardEncoding eq exch ISOLatin1Encoding eq or
{ 3 index ( dup /Encoding get ) writestring
StandardEncoding eq { (StandardEncoding) } { (ISOLatin1Encoding) } ifelse
3 index 1 index writestring
3 index ( ne { dup length dict copy dup /FID undef dup /Encoding ) writestring
3 index exch writestring
2 index ( put /_ exch definefont } if\n) writestring
}
{ 2 index ( dup length dict copy dup /FID undef dup /Encoding\n) writestring
2 index exch write#
1 index (\nput /_ exch definefont\n) writestring
}
ifelse
% Check for modified Metrics.
dup /Metrics .knownget
{ 2 index ( dup length dict copy\n) writestring
2 index ( dup /FID undef dup /UniqueID undef dup /Metrics\n) writestring
2 index exch write#
1 index (\nput /_ exch definefont\n) writestring
}
if pop pop
} bdef
/write#dict 10 dict dup begin
/arraytype
{ dup xcheck { (}) ({) } { (]) ([) } ifelse
2 index length 0 eq
{ 3 index exch writestring exch
}
{ 3 -1 roll
{ 3 index 2 index writestring 3 index exch write# pop ( ) }
forall
}
ifelse pop writestring
} bdef
/dicttype
{ null userdict { 3 index eq { exch pop exit } if pop } forall
dup null eq
{ pop 2 copy dup /FID known { fontwrite# } { dictwrite# } ifelse
1 index ( userdict ) writestring
uniqueid# 2 index 1 index write# 2 index ( 2 index put) writestring
userdict exch 3 -1 roll put pop
}
{ exch pop cvx write==only
}
ifelse
} bdef
/marktype
{ pop ([) writestring
} bdef
end def
/write#
{ dup type //write#dict exch .knownget { exec } { write==only } ifelse
} bind def
% Rebind the procedures that conditionally write out PostScript.
/# % <arg1> ... <argN> <opname> <N> # -
{ 1 index load 3 1 roll #exec
} bdef
/#? % - #? <writing>
{ /PSout where { pop true } { false } ifelse
} bdef
/#exec % <arg1> ... <argN> <proc|operator> <opname> <N> #exec -
{ /PSout where
{ pop -1 1 { 1 add index PSout exch write# PSout ( ) writestring } for
PSout exch write=
}
{ pop pop
}
ifelse exec
} bdef
/#dsc % mark <obj1> ... #dsc -
{ /PSout where
{ pop counttomark
{ counttomark -1 roll PSout exch write=only }
repeat pop PSout (\n) writestring
}
{ cleartomark
}
ifelse
} bdef
/iscomment % <line> iscomment <line> <bool>
{ dup () eq { true } { dup 0 1 getinterval (%) eq } ifelse
} bdef
/#dscfile % <filename> #dscfile -
{ /PSout where
{ pop findlibfile
{ exch pop }
{ (r) file } % let the error happen
ifelse
{ dup =string readline pop
iscomment { mark exch #dsc } { exit } ifelse
}
loop mark exch #dsc
{ dup =string readline not { pop exit } if
iscomment
{ pop }
{ (%) search { exch pop exch pop } if mark exch #dsc }
ifelse
}
loop closefile
}
{ pop
}
ifelse
} bdef
% Rebind Is, which constructs a data source for an image.
% pdf_draw defined it to simply retrieve the stream.
/Is_draw /Is load def
/EI_draw /EI load def
userdict /Is_string null put % establish a binding
userdict /Is_text null put % ditto
userdict /Is_data null put % ditto
/Is % <imagedict> Is <imagedict> <datasource>
{ /PSout where
{ pop dup /DataSource get string /Is_string exch store
/Is_text PSout /ASCII85Encode filter store
/Is_data Is_text Is_string length /RunLengthEncode filter store
Is_draw
{ Is_string readstring pop Is_data 1 index writestring }
aload length 1 add packedarray cvx
}
{ Is_draw
}
ifelse
} bdef
/EI
{ /PSout where { pop Is_data closefile Is_text closefile } { EI_draw } ifelse
} bdef
% Rebind readfontfilter, which constructs the filter that
% reads the text of an embedded Type 1 (and eventually Type 3) font.
/readfontfilter_orig /readfontfilter load def
/readfontfilter % <proc> readfontfilter <filter>
{ /copyfontdata cvx 2 array astore cvx
0 () /SubFileDecode filter
} bdef
/copyfontdata % <string> <origproc> copyfontdata <substring>
{ exec /PSout where { pop PSout 1 index writestring } if
} bdef
end % pdfdict
.setglobal
end % GS_PDF_ProcSet